﻿var columns =
            [
                 { display: 'Key', name: 'Id', type: 'text', hide: 1 },
                { display: '客户名称', name: 'ClientName', mintWidth: 80, width: 120 }, //, type: 'int', mintWidth: 40, width: 100
                {display: '客户编码', name: 'ClientCode', mintWidth: 100, width: 140},
                { display: '客户简称', name: 'ShortName', mintWidth: 100, width: 140 },
                { display: '电话', name: 'ClientPhone', mintWidth: 80, width: 120 },
                { display: '电子邮件', name: 'Email', mintWidth: 80, width: 120 },
                { display: '业务负责人', name: 'Name', mintWidth: 80, width: 120 },
                { display: '开户行', name: 'BankName', mintWidth: 150, width: 200 },
                { display: '银行账号', name: 'AccountNnmber', mintWidth: 100, width: 120 },
                 //  { display: '所属组织机构', name: 'OrgName', mintWidth: 100, width: 120 }, //未做映射(不需要显示)
                // { display: '删除状态', name: 'DeleteState', mintWidth: 80, width: 140 },
                 { display: '客户地址', name: 'ClientAddress', mintWidth: 100, width: 200 }
             ];

var manager;
$(document).ready(function () {
    $("#btnSearch").unbind("click").bind("click", initligerGrid);
    initligerGrid();
});

function initligerGrid() {
    manager = null;
    manager = $("#clientsGrid").ligerGrid({
        columns: columns,
        title: '客户信息管理',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [
                                    { text: '增加', click: dialogAdd, icon: 'add' },
                                    { line: true },
                                    { text: '修改', click: modifyOperation, icon: 'modify' },
                                    { line: true },
                                    { text: '删除', click: deleteOperation, img: '../Content/images/delete.gif' },
                                    { line: true },
                                    { text: '查看', click: dialogDetailView, img: '../Content/images/Search.png' }
                                    ]
        },
        parms: { orgCode: $("#HidOrgCode").val(), ClientName: $("#ClientName").val(), ClientCode: $("#ClientCode").val(), Deleted: ($("#Deleted").attr("checked") == true ? 1 : 0) },
        url: "../Client/GetClients?rand=" + Math.random(),
        onDblClickRow: function (data, rowindex, rowobj) { dialogView(data.Key); }
    });
}

//detail
function dialogDetailView() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要查看的行!'); return; }
    var billId = row.Key.toString();
    dialogView(billId);
  }
function dialogView(billId) {
    $.ligerDialog.open({ url: "../Client/ClientDetail?id=" + billId, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}
//add
function dialogAdd() {
    $.ligerDialog.open({ url: "../Client/Add?orgCode=" + $("#HidOrgCode").val(), height: getDialogHeight(), width: getDialogWidth(), 
    isResize: true, isHidden: false
    });
}

//delete
function deleteOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择需要删除行！'); return; }
    $.ligerDialog.confirm('确定要删除吗？', function (yes) {
        if (yes) {
            $.get("../Client/Delete?clientInfoId=" + row.Key, {}, function (data) {
                if (data != undefined && data == "9") {
                    initligerGrid();
                }
            });
        }
    });
}
//update 
function modifyOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要编辑的行!'); return;
    }
    $.ligerDialog.open({ url: "../Client/Add?clientId=" + row.Key + "&orgCode=" + $("#HidOrgCode").val(), height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });
}


